import http from "@/network/http"
import { TreasuryGoods } from "@/types"

export type TreasuryGoodsParams = Omit<TreasuryGoods, 'treasuryGoodsId' | 'remainCount' | 'createUserId' | 'createUserName'> & { exchangeNote?: string }

export const createTreasuryGoods = (params: TreasuryGoodsParams) => {
  return http.post({
    url: '/treasury/goods/create',
    data: params
  })
}

export const getTreasuryGoodsDetail = (treasuryGoodsId: number): Promise<TreasuryGoods> => {
  return http.get({
    url: '/treasury/goods/detail',
    data: { treasuryGoodsId }
  })
}

export interface ExchangeTreasuryGoodsParams {
  treasuryGoodsId: number
  treasuryId: number
}

export const exchageTreasuryGoods = (params: ExchangeTreasuryGoodsParams) => {
  return http.post({
    url: '/treasury/goods/exchange',
    data: params
  })
}

export interface DonateTreasuryGoodsParams extends ExchangeTreasuryGoodsParams {
  giftUserName: string
  note?: string
}

/*
 * 赠送商品
 */
export const donateTreasuryGoods = (params: DonateTreasuryGoodsParams) => {
  return http.post({
    url: '/treasury/goods/donate',
    data: params
  })
}